package com.mdinfo.gw.device.websocket.web;

import com.alibaba.fastjson.JSON;
import com.mdinfo.gw.device.websocket.endpoint.AlarmEndPoint;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by Administrator on 2017/12/18.
 */
@RestController
@RequestMapping("/test/alarm")
public class AlaramController {

    @Resource
    AlarmEndPoint alarmEndPoint;

    @RequestMapping("/send")
    public String send(){

        WsMessage message = new WsMessage();
        message.setContent("来自服务端的消息");
        message.setForm("server");
        message.setTime(new Date());
        message.setType("type");

        AlarmEndPoint.sendMessage(JSON.toJSONString(message));

        return "ok";
    }
}

@Data
class WsMessage{
    private String form;
    private Date time;
    private String type;
    private String content;
}
